﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Abp.Extension.CodeGenerater.Helper
{
    public class AssemblyHelper
    {

        public static Assembly Assembly;


        public static Assembly Load(string file)
        {
            Assembly = Assembly.LoadFile(file);
            return Assembly;
        }

        public static TreeNode GetClazzsTreeNode(string file)
        {
            TreeNode root = new TreeNode
            {
                Name = "Table",
                Text = "表"
            };
            Assembly assembly = Load(file);
            var modules = assembly.GetModules().ToList();

            foreach (var module in modules)
            {
                var types = module.GetTypes().ToList();
                foreach (var type in types)
                {
                    TreeNode child = new TreeNode();
                    child.Name = type.Name;
                    child.Text = type.Name + "[" + type.FullName + "]";
                    child.Tag = "T";
                    child.ToolTipText = type.Name;
                    root.Nodes.Add(child);
                }
            }

            return root;
        }

    }
}
